package com.zhl.scheduling.controller;

import com.zhl.scheduling.common.manger.LoginStatusManager;
import com.zhl.scheduling.model.vo.LoginVO;
import com.zhl.scheduling.model.vo.ResStatus;
import com.zhl.scheduling.model.vo.ResultVO;
import com.zhl.scheduling.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: ZhangLu In DLUT
 * @since: 1.0.0
 * @Description: 提供用户登录与登出相关的接口
 * @CrossOrigin：处理前后端跨域请求
 */

@Api(value = "提供用户登录等相关接口", tags = "用户相关")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    /**
     * controller 层一定有service的接口指向实现类
     */
    @Resource
    private UserService userService;

    @ApiOperation("用户登录接口")
    @PostMapping("/login")
    public ResultVO login(@Validated @RequestBody LoginVO loginVO){
        ResultVO resultVO = userService.checkLogin(loginVO.getUsername(), loginVO.getPassword(), loginVO.getUserType());
        return resultVO;
    }

    @GetMapping("/login/status")
    @ApiOperation("获取用户登录状态接口")
    public ResultVO getLoginStatus(){
        return userService.getLoginStatus();
    }

    @GetMapping("/logout")
    @ApiOperation("用户登出")
    public ResultVO logout(){
        return userService.logout();
    }
}
